home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / TextUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  10.5 KB  |  386 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        TextUtils.h
  3.  
  4.      Contains:    Text Utilities Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1985-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __TEXTUTILS__
  19. #define __TEXTUTILS__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. #ifndef __NUMBERFORMATTING__
  25. #include <NumberFormatting.h>
  26. #endif
  27. #ifndef __STRINGCOMPARE__
  28. #include <StringCompare.h>
  29. #endif
  30. #ifndef __DATETIMEUTILS__
  31. #include <DateTimeUtils.h>
  32. #endif
  33.  
  34.  
  35.  
  36. #if PRAGMA_ONCE
  37. #pragma once
  38. #endif
  39.  
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43.  
  44. #if PRAGMA_IMPORT
  45. #pragma import on
  46. #endif
  47.  
  48. #if PRAGMA_STRUCT_ALIGN
  49.     #pragma options align=mac68k
  50. #elif PRAGMA_STRUCT_PACKPUSH
  51.     #pragma pack(push, 2)
  52. #elif PRAGMA_STRUCT_PACK
  53.     #pragma pack(2)
  54. #endif
  55.  
  56. /*
  57.  
  58.     Here are the current System 7 routine names and the translations to the older forms.
  59.     Please use the newer forms in all new code and migrate the older names out of existing
  60.     code as maintainance permits.
  61.     
  62.     NEW NAME                    OLD NAMEs                    OBSOLETE FORM (no script code)
  63.  
  64.     FindScriptRun
  65.     FindWordBreaks                                            NFindWord, FindWord
  66.     GetIndString            
  67.     GetString
  68.     Munger
  69.     NewString                
  70.     SetString                
  71.     StyledLineBreak
  72.     TruncString
  73.     TruncText
  74.  
  75.     UpperString ($A054)            UprString, UprText
  76.     UppercaseText                SCUpperText (a only)        UpperText ($A456)
  77.     LowercaseText                                            LwrString, LowerText, LwrText ($A056)
  78.     StripDiacritics                                            StripText ($A256)
  79.     UppercaseStripDiacritics                                StripUpperText ($A656)
  80.  
  81.  
  82. */
  83.  
  84. /* Type for truncWhere parameter in TruncString, TruncText */
  85. typedef short                             TruncCode;
  86.  
  87. enum {
  88.                                                                 /* Constants for truncWhere argument in TruncString and TruncText */
  89.     truncEnd                    = 0,                            /* Truncate at end */
  90.     truncMiddle                    = 0x4000,                        /* Truncate in middle */
  91.     smTruncEnd                    = 0,                            /* Truncate at end - obsolete */
  92.     smTruncMiddle                = 0x4000                        /* Truncate in middle - obsolete */
  93. };
  94.  
  95.  
  96. enum {
  97.                                                                 /* Constants for TruncString and TruncText results */
  98.     notTruncated                = 0,                            /* No truncation was necessary */
  99.     truncated                    = 1,                            /* Truncation performed */
  100.     truncErr                    = -1,                            /* General error */
  101.     smNotTruncated                = 0,                            /* No truncation was necessary - obsolete */
  102.     smTruncated                    = 1,                            /* Truncation performed    - obsolete */
  103.     smTruncErr                    = -1                            /* General error - obsolete */
  104. };
  105.  
  106. typedef SInt8                             StyledLineBreakCode;
  107.  
  108. enum {
  109.     smBreakWord                    = 0,
  110.     smBreakChar                    = 1,
  111.     smBreakOverflow                = 2
  112. };
  113.  
  114. struct ScriptRunStatus {
  115.     SInt8                             script;
  116.     SInt8                             runVariant;
  117. };
  118. typedef struct ScriptRunStatus ScriptRunStatus;
  119.  
  120. struct BreakTable {
  121.     char                             charTypes[256];
  122.     short                             tripleLength;
  123.     short                             triples[1];
  124. };
  125. typedef struct BreakTable BreakTable;
  126.  
  127. typedef BreakTable *                    BreakTablePtr;
  128. struct NBreakTable {
  129.     SInt8                             flags1;
  130.     SInt8                             flags2;
  131.     short                             version;
  132.     short                             classTableOff;
  133.     short                             auxCTableOff;
  134.     short                             backwdTableOff;
  135.     short                             forwdTableOff;
  136.     short                             doBackup;
  137.     short                             length;                        /* length of NBreakTable */
  138.     char                             charTypes[256];
  139.     short                             tables[1];
  140. };
  141. typedef struct NBreakTable NBreakTable;
  142.  
  143. typedef NBreakTable *                    NBreakTablePtr;
  144. /* The following functions are new names that work on 68k and PowerPC*/
  145. EXTERN_API( long )
  146. Munger                            (Handle                 h,
  147.                                  long                     offset,
  148.                                  const void *            ptr1,
  149.                                  long                     len1,
  150.                                  const void *            ptr2,
  151.                                  long                     len2)                                ONEWORDINLINE(0xA9E0);
  152.  
  153. EXTERN_API( StringHandle )
  154. NewString                        (ConstStr255Param         theString)                            ONEWORDINLINE(0xA906);
  155.  
  156. EXTERN_API( void )
  157. SetString                        (StringHandle             theString,
  158.                                  ConstStr255Param         strNew)                                ONEWORDINLINE(0xA907);
  159.  
  160. EXTERN_API( StringHandle )
  161. GetString                        (short                     stringID)                            ONEWORDINLINE(0xA9BA);
  162.  
  163. EXTERN_API( void )
  164. GetIndString                    (Str255                 theString,
  165.                                  short                     strListID,
  166.                                  short                     index);
  167.  
  168. #if CGLUESUPPORTED
  169. EXTERN_API_C( void )
  170. setstring                        (StringHandle             theString,
  171.                                  const char *            strNew);
  172.  
  173. EXTERN_API_C( StringHandle )
  174. newstring                        (const char *            theString);
  175.  
  176. EXTERN_API_C( void )
  177. getindstring                    (char *                    theString,
  178.                                  short                     strListID,
  179.                                  short                     index);
  180.  
  181. #endif  /* CGLUESUPPORTED */
  182.  
  183. EXTERN_API( StyledLineBreakCode )
  184. StyledLineBreak                    (Ptr                     textPtr,
  185.                                  long                     textLen,
  186.                                  long                     textStart,
  187.                                  long                     textEnd,
  188.                                  long                     flags,
  189.                                  Fixed *                textWidth,
  190.                                  long *                    textOffset)                            FOURWORDINLINE(0x2F3C, 0x821C, 0xFFFE, 0xA8B5);
  191.  
  192. EXTERN_API( short )
  193. TruncString                        (short                     width,
  194.                                  Str255                 theString,
  195.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x8208, 0xFFE0, 0xA8B5);
  196.  
  197. EXTERN_API( short )
  198. TruncText                        (short                     width,
  199.                                  Ptr                     textPtr,
  200.                                  short *                length,
  201.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFDE, 0xA8B5);
  202.  
  203. EXTERN_API( void )
  204. FindWordBreaks                    (Ptr                     textPtr,
  205.                                  short                     textLength,
  206.                                  short                     offset,
  207.                                  Boolean                 leadingEdge,
  208.                                  BreakTablePtr             breaks,
  209.                                  OffsetTable             offsets,
  210.                                  ScriptCode             script)                                FOURWORDINLINE(0x2F3C, 0xC012, 0x001A, 0xA8B5);
  211.  
  212. EXTERN_API( void )
  213. LowercaseText                    (Ptr                     textPtr,
  214.                                  short                     len,
  215.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0000, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  216.  
  217. EXTERN_API( void )
  218. UppercaseText                    (Ptr                     textPtr,
  219.                                  short                     len,
  220.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0400, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  221.  
  222. EXTERN_API( void )
  223. StripDiacritics                    (Ptr                     textPtr,
  224.                                  short                     len,
  225.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0200, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  226.  
  227. EXTERN_API( void )
  228. UppercaseStripDiacritics        (Ptr                     textPtr,
  229.                                  short                     len,
  230.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0600, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  231.  
  232. EXTERN_API( ScriptRunStatus )
  233. FindScriptRun                    (Ptr                     textPtr,
  234.                                  long                     textLen,
  235.                                  long *                    lenUsed)                            FOURWORDINLINE(0x2F3C, 0x820C, 0x0026, 0xA8B5);
  236.  
  237. /*
  238.       The following functions are old names, but are required for PowerPC builds
  239.       because InterfaceLib exports these names, instead of the new ones.
  240. */
  241.  
  242. EXTERN_API( void )
  243. FindWord                        (Ptr                     textPtr,
  244.                                  short                     textLength,
  245.                                  short                     offset,
  246.                                  Boolean                 leadingEdge,
  247.                                  BreakTablePtr             breaks,
  248.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0x001A, 0xA8B5);
  249.  
  250. EXTERN_API( void )
  251. NFindWord                        (Ptr                     textPtr,
  252.                                  short                     textLength,
  253.                                  short                     offset,
  254.                                  Boolean                 leadingEdge,
  255.                                  NBreakTablePtr         nbreaks,
  256.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0xFFE2, 0xA8B5);
  257.  
  258. /*
  259.    On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  260.    return an error code in register D0, but System 7 PowerMacs do not emulate
  261.    this properly, so checking D0 is unreliable.
  262. */
  263.  
  264.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  265.                                                                                             #pragma parameter LwrText(__A0, __D0)
  266.                                                                                             #endif
  267. EXTERN_API( void )
  268. LwrText                            (Ptr                     textPtr,
  269.                                  short                     len)                                ONEWORDINLINE(0xA056);
  270.  
  271.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  272.                                                                                             #pragma parameter LowerText(__A0, __D0)
  273.                                                                                             #endif
  274. EXTERN_API( void )
  275. LowerText                        (Ptr                     textPtr,
  276.                                  short                     len)                                ONEWORDINLINE(0xA056);
  277.  
  278.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  279.                                                                                             #pragma parameter StripText(__A0, __D0)
  280.                                                                                             #endif
  281. EXTERN_API( void )
  282. StripText                        (Ptr                     textPtr,
  283.                                  short                     len)                                ONEWORDINLINE(0xA256);
  284.  
  285.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  286.                                                                                             #pragma parameter UpperText(__A0, __D0)
  287.                                                                                             #endif
  288. EXTERN_API( void )
  289. UpperText                        (Ptr                     textPtr,
  290.                                  short                     len)                                ONEWORDINLINE(0xA456);
  291.  
  292.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  293.                                                                                             #pragma parameter StripUpperText(__A0, __D0)
  294.                                                                                             #endif
  295. EXTERN_API( void )
  296. StripUpperText                    (Ptr                     textPtr,
  297.                                  short                     len)                                ONEWORDINLINE(0xA656);
  298.  
  299.  
  300. /* The following are new names which are exported by InterfaceLib*/
  301.  
  302. EXTERN_API( void )
  303. UpperString                        (Str255                 theString,
  304.                                  Boolean                 diacSensitive);
  305.  
  306. #if CGLUESUPPORTED
  307. EXTERN_API_C( void )
  308. upperstring                        (char *                    theString,
  309.                                  Boolean                 diacSensitive);
  310.  
  311. #endif  /* CGLUESUPPORTED */
  312.  
  313. /* The following are macros which map old names to the names exported by InterfaceLib*/
  314. #if OLDROUTINENAMES
  315. #define UprString(theString, diacSensitive)  \
  316.          UpperString(theString, diacSensitive)
  317. #if CGLUESUPPORTED
  318. #define uprstring(theString, diacSensitive) upperstring(theString, diacSensitive)
  319. #endif  /* CGLUESUPPORTED */
  320.  
  321. #endif  /* OLDROUTINENAMES */
  322.  
  323. /* Old routine name but no new names are mapped to it:*/
  324.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  325.                                                                                             #pragma parameter UprText(__A0, __D0)
  326.                                                                                             #endif
  327. EXTERN_API( void )
  328. UprText                            (Ptr                     textPtr,
  329.                                  short                     len)                                ONEWORDINLINE(0xA054);
  330.  
  331. /*
  332.  
  333.     Functions for converting between C and Pascal Strings
  334.     (Previously in Strings.h)
  335.     
  336. */
  337. EXTERN_API_C( StringPtr )
  338. c2pstr                            (char *                    aStr);
  339.  
  340. EXTERN_API( StringPtr )
  341. C2PStr                            (Ptr                     cString);
  342.  
  343. EXTERN_API_C( char *)
  344. p2cstr                            (StringPtr                 aStr);
  345.  
  346. EXTERN_API( Ptr )
  347. P2CStr                            (StringPtr                 pString);
  348.  
  349. EXTERN_API_C( void )
  350. c2pstrcpy                        (Str255                 dst,
  351.                                  const char *            src);
  352.  
  353. EXTERN_API_C( void )
  354. p2cstrcpy                        (char *                    dst,
  355.                                  ConstStr255Param         src);
  356.  
  357. EXTERN_API_C( void )
  358. CopyPascalStringToC                (ConstStr255Param         src,
  359.                                  char *                    dst);
  360.  
  361. EXTERN_API_C( void )
  362. CopyCStringToPascal                (const char *            src,
  363.                                  Str255                 dst);
  364.  
  365.  
  366. #if PRAGMA_STRUCT_ALIGN
  367.     #pragma options align=reset
  368. #elif PRAGMA_STRUCT_PACKPUSH
  369.     #pragma pack(pop)
  370. #elif PRAGMA_STRUCT_PACK
  371.     #pragma pack()
  372. #endif
  373.  
  374. #ifdef PRAGMA_IMPORT_OFF
  375. #pragma import off
  376. #elif PRAGMA_IMPORT
  377. #pragma import reset
  378. #endif
  379.  
  380. #ifdef __cplusplus
  381. }
  382. #endif
  383.  
  384. #endif /* __TEXTUTILS__ */
  385.  
  386.